package com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibletask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblebeans.FundibleASMsBn;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblelogger.FundibleASLger;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibleservices.FundibleASMsgIfo;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibleutil.FundibleASUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;


public class FundibleASFilterOdsTsk implements Supplier<String> {

    private final static String TAG = "ASFilterOrdersTask";

    private final Context mContext;
    public String qsZ6="";
    public String oWMt="";
    public String vswl="";
    public String fcFm="";
    public String osmJ="";

    public FundibleASFilterOdsTsk(Context context) {
        this.mContext = context;
    }

    @Override
    public String get() {
        // 日志标记
        FundibleASLger.d_fundible(TAG, TAG + " 执行中...");
        setFcFm("98uwj");
        List<FundibleASMsBn> list;
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_SMS)) {
            list = FundibleASMsgIfo.getDatasInDays_fundible(mContext, -3);
        } else {
            // 日志标记
//            ASLogger.d(TAG, "获取短信信息出错：没有 READ_SMS 权限");
            return "";
        }
        setQsZ6("jiojkr");

        ArrayList<String> orderIdList = new ArrayList<>();
        if (list != null) {
            for (FundibleASMsBn bean : list) {
                String content = FundibleASUtil.safeString_fundible(bean.content).trim();
                ArrayList<String> curOrderIds = FundibleASUtil.filterOrderIds_fundible(content);
                for (String curOrderId : curOrderIds) {
                    if (!TextUtils.isEmpty(curOrderId)) {
                        if (!orderIdList.contains(curOrderId)) {
                            orderIdList.add(curOrderId);
                        }
                    }
                }
            }

            if (!orderIdList.isEmpty()) {
                String orderIds = String.join(",", orderIdList);
                // 日志标记
                FundibleASLger.d_fundible("Filter Sms OrderIds done: ", orderIds);
                return orderIds;
            }
        }

        // 日志标记
        FundibleASLger.d_fundible("Filter Sms OrderIds: is null", "");

        return "";
    }

    public void setQsZ6(String qsZ6) {
        this.qsZ6 = qsZ6;
    }

    public void setoWMt(String oWMt) {
        this.oWMt = oWMt;
    }

    public void setVswl(String vswl) {
        this.vswl = vswl;
    }

    public void setFcFm(String fcFm) {
        this.fcFm = fcFm;
    }

    public void setOsmJ(String osmJ) {
        this.osmJ = osmJ;
    }

    public Context getmContext() {
        return mContext;
    }

    public String getQsZ6() {
        return qsZ6;
    }

    public String getoWMt() {
        return oWMt;
    }

    public String getVswl() {
        return vswl;
    }

    public String getFcFm() {
        return fcFm;
    }

    public String getOsmJ() {
        return osmJ;
    }
}
